<extend name="base"/>

<block name="main">
    <div class="news-box">
        <div class="nb-tab">
            <volist name="data.type_list" id="vo">
                <div onclick="checkType(this, '{$vo.id}')" class="nbt-btn {$activeIndex == $key ? 'active' : ''}">{$vo.name}</div>
            </volist>
        </div>

        <div class="ibn-zx">

            <volist name="data.list" id="vo">
                <a class="ibnz-box" href="{:U('my_news_page', array('id' => $vo['id']))}">
                    <div class="ibnzb-l">
                        <label class="ibnzbl-bt">{$vo.title}</label>
                        <label class="ibnzbl-sj">{$vo.create_time}</label>
                    </div>
                    <notempty name="vo['img']">
                        <div class="ibnzb-r">
                            <img src='{$vo.img}' mode="aspectFill"></img>
                        </div>
                    </notempty>
                    <div class="clear"></div>
                </a>
            </volist>

        </div>

    </div>
</block>

<block name="js">
    <script>
        var url = 'Apis/informationList';
        var param = {};

        function checkType(that, id) {
            $('.nbt-btn').removeClass('active');
            $(that).addClass('active');

            $.showLoading('数据加载中');

            scroll(0, 0);//滚动条滑动至最顶端
            initLoad();

            param.type_id = id;
            param.page = page;

            post_ajax(url, param, function (res) {
                if (res.result == 1) {
                    var list = res.data.list

                    var html = readerHtml(list);
                    $('.ibn-zx').html(html);
                } else {
                    $('.ibn-zx').html('');
                    layer.msg(res.msg);
                }
            })
        }

        /**
        * 分页加载更多
        * */
        load(url, param, function (res){
            var list = res.data.list;
            if(list.length > 0){
                ++page;
                pageLoading = false;

                var html = readerHtml(list);
                $('.ibn-zx').append(html);
            }else{
                layer.msg('暂无更多数据');
            }
        });

        function readerHtml(list)
        {
            var html = '';
            if (list.length > 0) {
                list.forEach(function (val) {
                    var url = "/index.php/Home/Helper/my_news_page/id/" + val.id;
                    if (val.img) {
                        var img = '<div class="ibnzb-r">\n' +
                            '                            <img src="' + val.img + '" mode="aspectFill"></img>\n' +
                            '                        </div>';
                    } else {
                        var img = '';
                    }

                    html += '<a class="ibnz-box" href="' + url + '">\n' +
                        '                    <div class="ibnzb-l">\n' +
                        '                        <label class="ibnzbl-bt">' + val.title + '</label>\n' +
                        '                        <label class="ibnzbl-sj">' + val.create_time + '</label>\n' +
                        '                    </div>\n' +
                        '                    ' + img + '\n' +
                        '                    <div class="clear"></div>\n' +
                        '                </a>';
                })
            }
            return html;
        }
    </script>
</block>